﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WS.EKA.Core.DI;
using WS.EKA.ServiceInterface;
using WS.EKA.Model;
using System.Web;
using System.Web.Security;
using Newtonsoft.Json;
using WS.EKA.Portal.Filters;
using AttributeRouting.Web.Http;

namespace WS.EKA.Portal.Controllers
{
    public class CollectController : ControllerBase
    {
        private IServiceFactory factory;
        private ICollect collectService;


        public CollectController(IServiceFactory factory)
        {
            this.factory = factory;
            collectService = factory.GetInterfaceImplement<ICollect>();

        }

        // GET api/collect/loginname
        public List<Collect> Get(string id)
        {
            return collectService.Get(id);
        }

        // POST api/collect
        public HttpStatusCode Post(Guid productGuid)
        {
            Collect model = new Collect()
            {
                CollectTime = DateTime.Now,
                Guid = Guid.NewGuid(),
                ProductGuid = productGuid,
                MemLoginID = GetCurrentUser()
            };
            collectService.Add(model);
            return HttpStatusCode.Accepted;
        }

        // DELETE api/collect/5
        [DELETE("api/collect/{CollectId}")]
        public HttpStatusCode Delete(Guid CollectId)
        {
            collectService.Delete(CollectId, GetCurrentUser());
            return HttpStatusCode.OK;
        }

    }
}
